<template>
  <div>
    <button @click="isShow = !isShow">切换</button>
    <!-- 使用transition组件包含被条件渲染的元素，控制其执行动画 -->
    <transition name="box1">
      <div class="box" v-if="isShow"></div>
    </transition>
    <br />
  </div>
</template>

<script>
export default {
  name: "App",
  data() {
    return {
      isShow: true,
    };
  },
};
</script>

<style>
.box {
  width: 100px;
  height: 100px;
  background: red;
}

@keyframes change {
  from {
    width: 20px;
    height: 20px;
    background-color: yellowgreen;
    transform: rotate(30deg);
  }

  50% {
    width: 100px;
    height: 20px;
    transform: rotate(-30deg);
  }
}

/* 控制过程的过渡动画 */
.box1-enter-active {
  animation: change 1s linear;
}

.box1-leave-active {
  animation: change 1s linear reverse;
}
</style>
